package win.liumian.sso.server.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import win.liumian.sso.server.dao.mapper.UserMapper;
import win.liumian.sso.server.dao.po.User;
import win.liumian.sso.server.dao.po.UserExample;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public User getUserBy(String username) {
        UserExample example = new UserExample();
        example.createCriteria().andUsernameEqualTo(username);
        List<User> users = userMapper.selectByExample(example);
        return users.isEmpty() ? null : users.get(0);


    }

    /**
     * 注册用户
     * @param username
     * @param password
     * @return
     */
    public User registerUser(String username, String password) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        userMapper.insertSelective(user);

        return user;
    }


}
